<template>
	<view class="">
		<navView :navTitle="is_one ? '合同付款' : '合同列表'" :titleColor="is_one ? '#fff' : '#333'" :isBack="true"></navView>
		<view class="topBox" v-if="is_one">
			<view class="stateList">
				<view :class="state_index == item.value ? 'items' : 'item'" v-for="(item, index) in stateList" :key="index"
					@tap="tapState(item.value)">
					{{ item.name }}
					<view class="tiao" v-if="state_index == item.value"></view>
				</view>
			</view>
		</view>
		<view v-if="is_one" style="height:80rpx">
		</view>
		<view class="project-list" v-if="is_one">
			<!-- 循环渲染每个项目 -->
			<view class="project-card" v-for="(project, index) in list" :key="index">
				<!-- 项目名称和状态 -->
				<view class="project-header">
					<text>{{project.contract_name}}</text>
				</view>
				<view class="contractCode">
					合同编码：{{project.contract_num}}
				</view>
				<!-- 功能标签栏 -->
				<view class="tab-bar">
					<text class="tab-item"
						@tap="$navTo('/subpkg/contract/contractDetail/contractDetail?id='+project.id)">合同详情</text>
					<text class="tab-item"
						@tap="$navTo('/subpkg/contract/contractState/contractState?id=' + project.project_info.id)">项目进度</text>
					<text class="tab-item" @tap="$navTo('/subpkg/contract/pay/pay?id='+project.id)">合同付款</text>
					<text class="tab-item"
						@tap="$navTo('/subpkg/contract/contractOrder/contractOrder?id='+project.id)">开票情况</text>
				</view>
			</view>
			<view v-if="!isLoading && list.length === 0" class="no-data-text">暂无合同数据</view>
		</view>
		<view class="capsule-box" v-else>
			<view class="project-list2">
				<!-- <view class="project-title">
					<view class="title">
						
					</view>
					<view class="right">
						更多
						<uni-icons type="right" size="22rpx" color="#B0B0B0"></uni-icons>
					</view>
				</view> -->
				<!-- 循环渲染每个项目 -->
				<view class="project-card" v-for="(project, index) in list" :key="index">
					<!-- 项目名称和状态 -->
					<view class="project-header">
						<text>{{project.name}}</text>

					</view>
					<view class="contractCode">
						合同编码：{{project.num}}
					</view>
					<!-- 功能标签栏 -->
					<view class="tab-bar">
						<text class="tab-item"
							@tap="$navTo('/subpkg/contract/contractDetail/contractDetail?id='+project.id)">合同详情</text>
						<text class="tab-item"
							@tap="$navTo('/subpkg/contract/contractState/contractState?id=' + project.project_id)">项目进度</text>
						<text class="tab-item" @tap="$navTo('/subpkg/contract/pay/pay?id='+project.id)">合同付款</text>
						<text class="tab-item"
							@tap="$navTo('/subpkg/contract/contractOrder/contractOrder?id='+project.id)">开票情况</text>
					</view>
				</view>
				<view v-if="!isLoading && list.length === 0" class="no-data-text">暂无合同数据</view>
			</view>
		</view>

	</view>
</template>

<script>
	export default {
		data() {
			return {
				stateList: [{
					name: '已付款',
					value: 1
				},
				{
					name: '已完成',
					value: 2
				},
				{
					name: '待付款',
					value: 3
				},
				],
				state_index: 1,  // 默认选中待付款（对应value=3）								
				isLoading: true,
				is_one: true,
				list: [],
				detail: {}
			}
		},
		onLoad(option) {
			console.log(option,'option')
			this.id = option.id
			if (option.id) {
				this.id = option.id
				this.getDetail()
				this.is_one = false
			} else {
				this.is_one = true
				this.getList()
			}
		},
		methods: {
			tapState(ind) {
				console.log(ind,'ind')
				this.state_index = ind
				this.getList()
			},
			getDetail() {
				this.$request('/addons/qingdong/contract/getProjectContractList', 'GET', {
					project_id: this.id
				}).then(res => {
					console.log(res)
					this.list = res.data
				})
			},
			getList() {
				this.$request('/addons/qingdong/contract/getUserContactStatusList', 'GET',{
					status_type: this.state_index,
					type: 0
				}).then(res => {
					console.log(res)
					this.list = res.data.data
				})
			},
			handleEvaluation(project) {
				uni.navigateTo({
					url: `/pages/evaluation/evaluation?projectId=${project.name}`,
				});
			},
		}
	}
</script>

<style lang="scss">
	.no-data-text {
		text-align: center;
		padding: 48rpx 0;
		color: #999;
		font-size: 24rpx;
	}
	.project-list {
		padding: 20rpx;
	}
		.topBox {
			width: 100%;
			position: fixed;
			left: 0;
			z-index: 100;
	
			.input-box {
				background: #008efe;
				display: flex;
				align-items: center;
				justify-content: space-between;
				padding: 10rpx 60rpx;
				box-sizing: border-box;
	
				.input {
					background: #fff;
					border-radius: 40rpx;
					padding: 10rpx 30rpx;
					box-sizing: border-box;
					display: flex;
					align-items: center;
	
					image {
						width: 34rpx;
						height: 34rpx;
					}
	
					input {
						padding-left: 20rpx;
						box-sizing: border-box;
					}
				}
	
				.shai {
					width: 44rpx;
					height: 44rpx;
				}
			}
	
			.stateList {
				width: 100%;
				background: #fff;
				display: flex;
				align-items: center;
				justify-content: space-around;
	
				.items {
					font-weight: bold;
					font-size: 30rpx;
					color: #008EFE;
					position: relative;
					padding: 20rpx 0;
	
					.tiao {
						width: 38rpx;
						height: 4rpx;
						background: #64AFFF;
						border-radius: 2rpx 2rpx 2rpx 2rpx;
						position: absolute;
						bottom: 0rpx;
						left: 50%;
						transform: translate(-50%);
					}
				}
	
				.item {
					font-size: 30rpx;
					color: #AFAFB2;
					padding: 20rpx 0;
				}
			}
		}
	.project-card {
		background-color: #fff;
		border-radius: 10rpx;
		overflow: hidden;
		margin-bottom: 20rpx;
		padding: 20rpx;
		box-shadow: 0rpx 0rpx 15rpx 0rpx #ccc;

		.project-header {
			display: flex;
			justify-content: space-between;
			align-items: center;
			margin-bottom: 10rpx;

			text {
				font-size: 32rpx;
				font-weight: bold;
			}

		}

		.contractCode {
			font-weight: 400;
			font-size: 24rpx;
			color: #7D7D7D;
			margin-top: 20rpx;
			padding: 20rpx 0;
			border-top: 1rpx dashed #7D7D7D;
		}

		.tab-bar {
			display: flex;
			justify-content: space-between;

			.tab-item {
				width: 20%;
				text-align: center;
				padding: 8rpx 0;
				background-color: #e0f1ff;
				border-radius: 10rpx;
				color: #007aff;
				font-size: 24rpx;
			}
		}


	}

	.capsule-box {
		padding: 20rpx;
		box-sizing: border-box;

		.project-list2 {
			background-color: #fff;
			box-shadow: 0rpx 0rpx 15rpx 0rpx #ccc;
			border-radius: 16rpx;

			.project-title {
				background: #e5f3fe;
				display: flex;
				align-items: center;
				justify-content: space-between;
				padding: 25rpx 20rpx;
				border-radius: 16rpx;
				padding-bottom: 40rpx;

				.title {
					font-size: 32rpx;
				}

				.right {
					display: flex;
					align-items: center;
					color: #B0B0B0;
					font-size: 22rpx;
				}
			}

			.project-card:first-child {
				border-radius: 16rpx;
				position: relative;
				margin-top: -16rpx;
				background: #fff;
			}

			.project-card {
				overflow: hidden;
				margin-bottom: 20rpx;
				padding: 20rpx;

				.project-header {
					display: flex;
					justify-content: space-between;
					align-items: center;
					margin-bottom: 10rpx;

					text {
						font-size: 32rpx;
						font-weight: bold;
					}

				}

				.contractCode {
					font-weight: 400;
					font-size: 24rpx;
					color: #7D7D7D;
					margin-top: 20rpx;
					padding: 20rpx 0;
					border-top: 1rpx dashed #7D7D7D;
				}

				.tab-bar {
					display: flex;
					justify-content: space-between;

					.tab-item {
						width: 20%;
						text-align: center;
						padding: 8rpx 0;
						background-color: #e0f1ff;
						border-radius: 10rpx;
						color: #007aff;
						font-size: 24rpx;
					}
				}
			}
		}
	}
</style>